﻿/*
 * @Autor: PK
 * @Date: 2022/01/26 13:20:SS
 */

using System.Collections.Generic;
using System.Windows.Forms;
using ShkSimulation.core.optimization.interfaces;
using ShkSimulation.core.util;

namespace ShkSimulation.desktop.component.tools {

	public class FormulaEvaluationStrategy:ResultEvaluationStrategy {

		public string Formula { get; set; }

		public FormulaEvaluationStrategy(string formula) {
			Formula = formula;
		}

		public double Evaluate(Dictionary<string, double> targetVariables) {
			(bool success, double value) = MathUtil.Execute(Formula, targetVariables);
			if (!success) {
				MessageBox.Show(@"评估函数有错:" + Formula, @"提示");
			}
			return value;
		}

	}

}